var  link=document.querySelectorAll("a")
var link=Array.from(link)
var closeBtn=document.querySelector("#close")
console.log(link)
console.log(closeBtn)

//----------------注意事项弹窗----------
for(let i=0;i<link.length;i++){
    //淡进淡出
    link[i].addEventListener("click",function(event){
        var tip=document.querySelector(".tip")
        tip.style.zIndex ="3"
        tip.style.opacity="1.0";
        console.log("跳进来改变透明度")
    })
}

closeBtn.addEventListener("click",function(event){
    var tip=document.querySelector(".tip")
    tip.style.opacity=0;
    tip.style.zIndex ="-1"
    console.log("跳进来隐藏")
})

//--------------form---------------
console.log(formSumbit)
for(let i=0; i<formSumbit.length;i++){
    formSumbit[i].addEventListener("click",function(e){
        var userName = document.querySelectorAll("input[name=userName]")
        var city = document.querySelectorAll("input[name=city]")
        var tel = document.querySelectorAll("input[name=tel]")
        var eMail=document.querySelectorAll("input[name=eMail]")
        var allow =document.querySelectorAll("#allow")
        console.log([userName])
        console.log(city)
        console.log(tel)
        console.log(eMail)
        console.log(allow)

        
        judgement(userName[i],1);
        judgement(city[i],2);
        judgement(tel[i],3);
        judgement(eMail[i],4);
        function isAllow(){
            return allow[i].checked==true;
        }
        var isAllow = isAllow();
        if(!isAllow){
            e.preventDefault();
        }

        function  judgement(inputType,num){
            inputType.addEventListener("click",function(){
                inputType.style.borderColor="skyblue";
                inputType.style.color="black"; 
            })
            if(!inputType.value){
                inputType.style.borderColor="red";          
                inputType.setAttribute("placeholder","Пожалуйста, введите");
                e.preventDefault();
            }
            else{
                switch (num) {
                    case 1:
                        userName_test()
                        break;
                    case 2:
                        city_test()
                        break;
                    case 3:
                       tel_test();
                        break;
                    case 4:
                       eMail_test();
                        break;
                    default:
                        break;
                }
        
                function userName_test(){
                    var reg=/^[\u4E00-\u9FA5]{2,4}$/;   /*定义验证表达式*/
                    console.log(reg.test(inputType.value))
                    if (!reg.test(inputType.value))
                    {
                        
                        inputType.value="请输入正确名字"
                        inputType.style.borderColor="red"; 
                        inputType.style.color="red"; 
                        e.preventDefault();
                    }     /*进行验证*/
                }
                function city_test(){
                    var reg=/^[\u4E00-\u9FA5]{2,4}$/;   /*定义验证表达式*/
                    console.log(reg.test(inputType.value))
                    if (!reg.test(inputType.value))
                    {
                        
                        inputType.value="请输入正确城市"
                        inputType.style.borderColor="red"; 
                        inputType.style.color="red"; 
                        e.preventDefault();
                    }     
                }

                function tel_test(){
                    var reg= /^((010|021|022|023|024|025|026|027|028|029|852)-\d{8})|(0?(13|14|15|18)[0-9]{9})$/;
                    if (!reg.test(inputType.value))
                    {
                        
                        inputType.value="请输入正确电话号码"
                        inputType.style.borderColor="red"; 
                        inputType.style.color="red"; 
                        e.preventDefault();
                    } 
                }    
                function eMail_test(){
                    var reg= /^([A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4})$/ 
                    if (!reg.test(inputType.value))
                    {
                        inputType.value="请输入正确邮箱"
                        inputType.style.borderColor="red"; 
                        inputType.style.color="red"; 
                        e.preventDefault();
                    }     
                }
            }
        }

    })
}



